﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevBox
{
    public class DevBoxLogger : ILogger
    {
        public string _categoryName { get; set; }
        public DevBoxLogger(string categoryName)
        {
            _categoryName = categoryName;
        }
        public IDisposable BeginScope<TState>(TState state)
        {
            return null;
        }

        public bool IsEnabled(LogLevel logLevel)
        {
            if (logLevel== LogLevel.Debug)
            {
                Console.WriteLine(_categoryName);
            }
            return true;
        }

        public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
        {
            var message = new
            {
                categoryName = _categoryName,
                Body = state
            };
            var color = ConsoleColor.DarkGreen;
            switch (logLevel)
            {
                case LogLevel.Trace:
                    break;
                case LogLevel.Debug:
                    break;
                case LogLevel.Information:
                    break;
                case LogLevel.Warning:
                    color = ConsoleColor.Yellow;
                    break;
                case LogLevel.Error:
                    color = ConsoleColor.Red;
                    break;
                case LogLevel.Critical:
                    color = ConsoleColor.Red;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            Console.ForegroundColor = color;
            Console.WriteLine("");
            Console.WriteLine("===================================================================================");
            Console.WriteLine(message?.ToIndentedJson());
            Console.Write("");
        }


    }
}
